 #coding=utf-8
__author__ = 'Administrator'
import cookielib
import urllib
import urllib2

#模拟登录战网
def login_zw(user,pwd):
    url = 'https://www.battlenet.com.cn/login/zh/index?ref=http://www.battlenet.com.cn/zh/&app=com-root'
    post_dict = {
        'csrftoken':'cdcca8f9-ddd4-4882-ae4d-3d4b0da29f90',
        'password':pwd,
        'accountName':user
    }
    post_data = urllib.urlencode(post_dict)
    print(post_data)

    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)

    response1 = urllib2.urlopen(url)
    print(response1.info())
    html = response1.read()
    print(html)

#
#    request = urllib2.Request(url,post_data)
#    request.add_header('Content-Type', "application/x-www-form-urlencoded")
#    response = urllib2.urlopen(request)
#
#    for index,cookie in enumerate(cj):
#        print(index,':',cookie)
#
#    print(check_cookie(cj))


#检查Cookie值是否存在
def check_cookie(cj):
    cookie_dict = {'login.key':False}
    for cookie in cj:
        if(cookie.name in cookie_dict):
            return True
        return False

#使用测试
if __name__ == '__main__':
  login_zw('545127804@qq.com','m8382117')
  login_zw('545127804@qq.com','2456546')